package fr.upstlse.glre.client.login;

import static fr.upstlse.glre.client.RfgConstante.LOGIN_FIELD_SUBMIT_LABEL;
import static fr.upstlse.glre.client.RfgConstante.LOGIN_PANEL_TITLE;

import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;

import fr.upstlse.glre.client.login.action.LoginAction;
import fr.upstlse.glre.client.widgets.fields.LoginFields;

public class Login {

	LoginFields loginFields;
	Window loginWindow;

	public Login() {
		createLoginPanel();
	}

	private void createLoginPanel() {
		loginWindow = new Window();
		loginWindow.setWidth(450);
		loginWindow.setModal(true);
		loginWindow.setClosable(true);
		loginWindow.setHeading(LOGIN_PANEL_TITLE);

		FormPanel lFormContentPanel = new FormPanel();
		lFormContentPanel.setHeaderVisible(false);
		lFormContentPanel.setWidth(400);
		lFormContentPanel.setFieldWidth(200);
		lFormContentPanel.setLabelWidth(100);

		loginFields = new LoginFields(lFormContentPanel);

		Button lValiderButton = new Button();
		lValiderButton.setText(LOGIN_FIELD_SUBMIT_LABEL);
		lValiderButton.addSelectionListener(new LoginAction(this));
		lFormContentPanel.addButton(lValiderButton);

		loginWindow.add(lFormContentPanel);
		loginWindow.show();

	}

	public LoginFields getLoginFields() {
		return loginFields;
	}

	public void setLoginFields(LoginFields loginFields) {
		this.loginFields = loginFields;
	}

	public Window getLoginWindow() {
		return loginWindow;
	}

	public void setLoginWindow(Window loginWindow) {
		this.loginWindow = loginWindow;
	}

}
